home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Mac OS USB DDK / Examples / USBSampleStorageDriver / SampleStorageHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-16  |  5.1 KB  |  171 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SampleStorageHeader.c
  3.  
  4.     Contains:    All exported structures and functions for the USB Manager
  5.  
  6.     Version:        1.1
  7.  
  8.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Craig Keithley
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            USB Drivers
  17.  
  18.     Writers:
  19.  
  20.         (TM)    Tim McLeod
  21.         (CJK)    Craig Keithley
  22.  
  23.     Change History (most recent first):
  24.  
  25.       <USB3>     2/16/99    TM            Added correct information to the Interface info in the driver
  26.                                     descriptor. Set the kDoNotMatchGeneric flag in the flags.
  27.       <USB2>     1/11/99    CJK        update to use sources from 1.1f3 DDK
  28.  
  29. */
  30.  
  31.  
  32.  
  33. #include <MacTypes.h>
  34. #include <Devices.h>
  35. #include <DriverServices.h>
  36. #include <USB.h>
  37.  
  38. #include "SampleStorageDriver.h"
  39. #include "SampleStorageVersion.h"
  40. #include "SampleStorageDeviceID.h"
  41.  
  42. //------------------------------------------------------
  43. //
  44. // Protos
  45. //
  46. //------------------------------------------------------
  47. OSStatus StorageDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc);
  48. OSStatus StorageDriverInitDevice(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  49. OSStatus StorageDriverInitInterface( UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc, USBDeviceDescriptor *deviceDesc, USBDeviceRef device);
  50. OSStatus StorageDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr desc );
  51. OSStatus    StorageDriverNotifyProc(UInt32     notification, void *pointer, UInt32 refCon);
  52.  
  53. //------------------------------------------------------
  54. //
  55. //    This is the driver description structure that the expert looks for first.
  56. //  If it's here, the information within is used to match the driver
  57. //  to the device whose descriptor was passed to the expert.
  58. //    Information in this block is also used by the expert when an
  59. //  entry is created in the Name Registry.
  60. //
  61. //------------------------------------------------------
  62. USBDriverDescription    TheUSBDriverDescription = 
  63. {
  64.     // Signature info
  65.     kTheUSBDriverDescriptionSignature,    // 'usbd'
  66.     kInitialUSBDriverDescriptor,            // 0
  67.     
  68.     // Device Info
  69.     kDriverVendorID,                            // USB Vendor ID
  70.     kDriverProductID,                            // USB Product ID.
  71.     0,                                                // Release Number of Device
  72.     0,                                                // Protocol Info.
  73.     
  74.     // Interface Info    (* I don't think this would always be required...*)                
  75.     0,                                                // Configuration Value
  76.     0,                                                // Interface Number
  77.     kDriverClassID,                            // Interface Class        (from USBDeviceDefines.h)
  78.     kDriverSubClassID,                         // Interface SubClass    (from USBDeviceDefines.h)
  79.     0,                                                // Interface Protocol
  80.         
  81.     
  82.     // Driver Info    
  83.     "\pUSB Storage Class",                    // Driver name for Name Registry
  84.     kDriverClassID,                            // Device Class              (from USBDeviceDefines.h)
  85.     kDriverSubClassID,                        // Device Subclass         (from USBDeviceDefines.h)
  86.     kStorageHexMajorVers, kStorageHexMinorVers, kStorageReleaseStage, kStorageCurrentRelease,        // version of driver = 0.0d0
  87.     
  88.     // Driver Loading Info
  89.     kUSBDoNotMatchGenericDevice    |        /* Driver's VendorID must match Device's VendorID*/
  90.     //kUSBDoNotMatchInterface        |        /* Do not load this driver as an interface driver.*/
  91.     //kUSBProtocolMustMatch            |        /* Do not load this driver if protocol field doesn't match.*/
  92.     //kUSBInterfaceMatchOnly        |        /* Only load this driver as an interface driver.*/
  93.     0                                                // To end the Driver Loading flags field
  94. };
  95.     
  96. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  97. {
  98.     kClassDriverPluginVersion,                // Version of this structure
  99.     StorageDriverValidateHW,                // Hardware Validation Procedure
  100.     StorageDriverInitDevice,                // Initialization Procedure
  101.     StorageDriverInitInterface,            // Interface Initialization Procedure
  102.     StorageDriverFinalize,                    // Finalization Procedure
  103.     StorageDriverNotifyProc,                // Driver Notification Procedure
  104. };
  105.  
  106. // Hardware Validation
  107. // Called upon load by Expert
  108. OSStatus 
  109. StorageDriverValidateHW(    USBDeviceRef            device,
  110.                                     USBDeviceDescriptor    *desc)
  111. {
  112.     device = 0;
  113.     desc = 0;
  114.     return (OSStatus)noErr;
  115. }
  116.  
  117.  
  118. // Initialization function
  119. // Called upon load by Expert
  120. OSStatus 
  121. StorageDriverInitDevice(    USBDeviceRef                device,
  122.                                     USBDeviceDescriptorPtr    pDesc,
  123.                                     UInt32                        busPowerAvailable)
  124. {
  125.     busPowerAvailable = 0;
  126.     
  127.     StorageDriverEntry(device, pDesc, NULL );
  128.     
  129.     return (OSStatus)noErr;
  130. }
  131.  
  132. // StorageDriverInitInterface function
  133. // Called to initialize driver for an individual interface - either by expert or
  134. // internally by driver
  135. OSStatus
  136. StorageDriverInitInterface(    UInt32                         interfaceNum, 
  137.                                         USBInterfaceDescriptor    *interfaceDesc, 
  138.                                         USBDeviceDescriptor        *deviceDesc, 
  139.                                         USBDeviceRef                 device)
  140. {
  141.     interfaceNum = 0;
  142.  
  143.     StorageDriverEntry(device, deviceDesc, interfaceDesc );
  144.     
  145.     return (OSStatus)noErr;
  146. }
  147.  
  148. // Termination function
  149. // Called by Expert when driver is being shut down
  150. OSStatus
  151. StorageDriverFinalize(    USBDeviceRef                device,
  152.                                 USBDeviceDescriptorPtr    desc )
  153. {
  154. #pragma unused(device)
  155. #pragma unused(desc)
  156.  
  157.     StorageClassDriverFinalize();
  158.  
  159.     return (OSStatus)noErr;
  160. }
  161.  
  162. OSStatus    
  163. StorageDriverNotifyProc(UInt32    notification,
  164.                                 void*        pointer,
  165.                                 UInt32    refCon)
  166. {
  167. #pragma unused(refCon)
  168.  
  169.     return(StorageClassDriverNotifyProc(notification, pointer));
  170. }
  171.